<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-12-04 01:20:39
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-02-25 16:13:15
 * @FilePath: /vue-element-admin/src/views/dashboard/admin/components/PieChart.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {
  countCustomerChannelApi,
} from "@/api/dashboard";
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      seriesDatas:[]
    }
  },
  
  async mounted() {
    
    this.$nextTick(async () => {
    await  this.countCustomerChannelApi()

    await  this.initChart()

    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    async countCustomerChannelApi() {
    await  countCustomerChannelApi().then((response) => {
    const array=  response.data;
       this.seriesDatas=array.map((item)=>{
        let obj={
          name:  item.channel?item.channel:'无',
          value: item.customerCount
        }
     return obj
       }
      )

       console.log("🍓",this.monthDatas)
      });
    },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['宠物医院', '抖音', '大众点评', '美团', '其他','无']
        },
        series: [
          {
            name: '客户渠道',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '38%'],
            data: 
            this.seriesDatas
            // [
            //   { value: 320, name: '宠物医院' },
            //   { value: 240, name: '抖音' },
            //   { value: 149, name: '大众点评' },
            //   { value: 100, name: '美团' },
            //   { value: 59, name: '其他' },
            //   { value: 100, name: '无' },

            // ]
            ,
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
